Office Word转换小工具 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles ConvertButton.Click
If Path.Text = "" Then
MsgBox("请浏览源文件!", MsgBoxStyle.Information, "提示")
Return
Else
If RadioButton1.Checked = True Then
If OpenFileDialog1.FilterIndex = 1 Then
Dim objApp As Object
'wdFormatDocument97=Offcie2003Format---doc;wdFormatDocumentDefault=Office2007Format---docx
Dim strDocName As String
Dim strDocSaveName As String
objApp = CreateObject("Word.Application")
Dim oDocLFormat As Object = Word.WdSaveFormat.wdFormatDocumentDefault
strDocName = Path.Text
'strDocSaveName = Application.StartupPath & "\TestSaveDoc.doc"
strDocSaveName = OpenFileDialog1.FileName & ".docx"
' OPEN--------------------------
objApp.Documents.Open(strDocName)
' SAVE AS-----------------------
objApp.Activedocument.SaveAs(FileName:=strDocSaveName, FileFormat:=oDocLFormat)
' CLOSE-------------------------
objApp.Activedocument.Close()
PathD.Text = strDocSaveName
MsgBox("转换成功!", MsgBoxStyle.Information, "成都优译信息技术")
Else
MsgBox("你当前选择的不是Office2003文档,要转换为Office2007及以上的Office文档请选择后缀为.doc的文档!", MsgBoxStyle.Information, "成都优译信息技术")
End If
ElseIf RadioButton2.Checked = True Then
If OpenFileDialog1.FilterIndex = 2 Then
Dim objApp As Object
'wdFormatDocument97=Offcie2003Format---doc;wdFormatDocumentDefault=Office2007Format---docx
Dim strDocName As String
Dim strDocSaveName As String
objApp = CreateObject("Word.Application")
Dim oDocLFormat As Object = Word.WdSaveFormat.wdFormatDocument97
strDocName = Path.Text
'strDocSaveName = Application.StartupPath & "\TestSaveDoc.doc"
strDocSaveName = OpenFileDialog1.FileName & ".doc"
' OPEN--------------------------
objApp.Documents.Open(strDocName)
' SAVE AS-----------------------
objApp.Activedocument.SaveAs(FileName:=strDocSaveName, FileFormat:=oDocLFormat)
' CLOSE-------------------------
objApp.Activedocument.Close()
PathD.Text = strDocSaveName
MsgBox("转换成功!", MsgBoxStyle.Information, "成都优译信息技术")
Else
MsgBox("你当前选择的不是Office2007及以上的Office文档,要转换为Office2003的Office文档请选择后缀为.docx的文档!", MsgBoxStyle.Information, "成都优译信息技术")
End If
End If
End If
End Sub
评论